﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the Microsoft Public License (Ms-PL).
// See accompanying file License.txt or copy at http://mews.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Mews.Application
{
    using System;
    using System.IO;

    using Mews.Application.Properties;

    /// <summary>Lets the user select the data directory of the application.</summary>
    internal sealed partial class DataDirectoryForm : DoneCancelForm
    {
        private const FileAttributes StorageCardAttributes = FileAttributes.Directory | FileAttributes.Temporary;

        internal DataDirectoryForm(string applicationName) : base(null, Resources.DataDirectory, false, false, false)
        {
            this.InitializeComponent();

            this.dataDirectoriesListBox.Items.Add(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), applicationName));

            foreach (var directoryInfo in new DirectoryInfo("\\").GetDirectories())
            {
                if ((directoryInfo.Attributes & StorageCardAttributes) == StorageCardAttributes)
                {
                    this.dataDirectoriesListBox.Items.Add(Path.Combine(directoryInfo.FullName, applicationName));
                }
            }

            this.dataDirectoriesListBox.SelectedIndex = 0;
        }

        internal string SelectedStorageLocation
        {
            get { return (string)this.dataDirectoriesListBox.SelectedItem; }
        }
    }
}
